{% load static %}
<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>DTU区间列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="/static/css/font.css">
    <link rel="stylesheet" href="/static/css/xadmin.css">
    <script src="/static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/js/xadmin.js"></script>
    <script type="text/javascript" src="/static/js/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="/static/js/jquery.cookie.js"></script>
    <script src="/static/js/flow-meter.js" charset="utf-8"></script>
    <!--[if lt IE 9]>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
</head>

<body>
<div class="x-nav">
    <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">
            <cite>DTU区间列表</cite>
        </a>
    </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5">
                        <div class="layui-inline layui-col-md2">
                            <input type="text" name="query_box" placeholder="请输入供气商名称\联系电话\备注" autocomplete="off"
                                   class="layui-input" id="query_box">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn" lay-submit="" lay-filter="search">
                                <i class="layui-icon">&#xe615;</i>
                            </button>
                        </div>
                    </form>
                </div>
                <div class="layui-card-body ">
                    <table lay-filter="dtu_region" id="dtu_region">
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/html" id="toolbarDemo">
    <button class="layui-btn layui-btn-danger" lay-event="del_batch">
        <i class="layui-icon"></i>批量删除
    </button>
    <button class="layui-btn" onclick="xadmin.open('添加DTU区间','/dtu_region/add/',700,400)">
        <i class="layui-icon"></i>添加
    </button>
</script>
<script>
    layui.use(['table', 'form', 'jquery', 'element', 'tree'],
        function () {
            $ = layui.jquery;
            table = layui.table;
            form = layui.form;

            table.render({
                elem: '#dtu_region', //指定原始表格元素选择器（推荐id选择器）
                cols: [[
                    {checkbox: true, width: '5%', field: 'id'},
                    {
                        numbbers: true,
                        width: '5%',
                        title: '序号',
                        templet: function (data) {
                            return data.LAY_INDEX;
                        }
                    },
                    {field: 'manufacturer_name', title: '供气商名称'},
                    {field: 'manufacturer_phone', title: '联系电话'},
                    {field: 'left', title: 'DTU起始编号'},
                    {field: 'total_num', edit: 'text', title: 'DTU最大数量'},
                    {field: 'used_num', title: 'DTU已使用数量'},
                ]],
                url: '/handler/dtu_region/?action=query_dtu_region',
                page: true,
                toolbar: '#toolbarDemo',
                defaultToolbar: [],

            });
            //监听单元格编辑
            table.on('edit(dtu_region)',
                function (obj) {
                    let data = obj.data;
                    delete data.manufacturer_name;
                    delete data.manufacturer_phone;
                    delete data.used_num;
                    delete data.left;
                    post({
                        "param": JSON.stringify(data),
                        "action": "update_dtu_region"
                    }, '/handler/dtu_region/', function (data) {
                        if (!data.success) {
                            layer.msg(data.msg, {icon: 5, time: 2000});
                        }
                    });
                });

            //头工具栏事件
            table.on('toolbar(dtu_region)',
                function (obj) {
                    var checkStatus = table.checkStatus(obj.config.id);
                    switch (obj.event) {
                        case 'del_batch':
                            layer.confirm('确认要删除吗？', function (index) {
                                let checkStatus = table.checkStatus('dtu_region');
                                let ids = [];
                                for (let i = 0; i < checkStatus.data.length; i++) {
                                    ids.push(checkStatus.data[i].id);
                                }
                                post({
                                    "param": JSON.stringify({'dtu_region_ids': ids}),
                                    "action": "del_batch_dtu_region"
                                }, '/handler/dtu_region/', function (data) {
                                    if (!data.success) {
                                        layer.msg(data.msg, {icon: 5, time: 1000});
                                    } else {
                                        layer.msg('删除成功!', {icon: 1});
                                        table.reload('dtu_region');
                                    }
                                });
                            });
                            break;
                    }
                });
            //监听提交
            form.on('submit(search)',
                function (data) {
                    table.reload('dtu_region', {
                        "where": {
                            "param": JSON.stringify(data.field),
                        }
                    });
                    return false;
                });


        });
</script>
<script>var _hmt = _hmt || [];
(function () {

})();</script>

</html>